package light.head.job;

import java.util.Date;
import java.util.List;

import light.head.dao.oa.ResignationDAO;
import light.head.dao.oa.TaskDAO;
import light.head.dao.sys.MessageDAO;
import light.head.framework.utils.DateUtils;
import light.head.model.Resignation;
import light.head.model.Task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 *提醒处理离职
 * @author yy
 */
@Service
public class CreatePayrollJob {
	
	private ResignationDAO resDAO;
	private MessageDAO msgDAO;
	private TaskDAO tDAO;
	
	private Boolean iswork = false;
	
	public void execute() {
		
		// 判断是否在执行
		if (iswork) {
			return;
		}
		// 获取任务信息
		List<Task> tList = tDAO.findTime(DateUtils.getDateStr(new Date(), "yyyy-MM-dd"));
		if (tList != null && tList.size() > 0) {
			for(Task t : tList){
				msgDAO.sendToUsers("您有任务需要在" + t.getEnd() +"之前完成,请尽快处理！", null , 0, t.getOc(), t.getUser());
			}
		}
		// 获取离职信息
		List<Resignation> reList = resDAO.findTime(DateUtils.getDateStr(new Date(), "yyyy-MM-dd"));
		if (reList != null && reList.size() > 0) {
			for(Resignation re : reList){
				msgDAO.sendToUsers("【" + re.getCn() + "】预计在" + re.getFt() +"离职,请尽快处理！", null , 0, re.getOc(), re.getCu());
			}
		}
		iswork = true;
	}
	
	
	@Autowired
	public void setResDAO(ResignationDAO resDAO) {
		this.resDAO = resDAO;
	}
	@Autowired
	public void setMsgDAO(MessageDAO msgDAO) {
		this.msgDAO = msgDAO;
	}

	@Autowired
	public void settDAO(TaskDAO tDAO) {
		this.tDAO = tDAO;
	}
	
}
